package com.example.study_manger.repository;

import com.example.study_manger.entity.Role;
import com.example.study_manger.entity.UserTb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserTbRe extends JpaRepository<UserTb, Long> , JpaSpecificationExecutor<UserTb> {
    UserTb findByUsernameAndPassword(String username, String password);

    Boolean existsByUsername(String username);

    UserTb findByUsername(String userName);
    @Query("select u.role.organization.id from UserTb u where u.username = ?1")
    String findOrgizationIdByUsername(String username);
    @Query("select u from UserTb u where u.role.organization.id = ?1")
    List<UserTb> findUserByOrgId(String organizationId);

    @Query("select u from UserTb u where u.username = ?1")
    UserTb findUserByUsername(String name);

    Page<UserTb> findAllByRoleIn(List<Role> allByRoleName, PageRequest of);
}
